package com._51cto.healthy.controller;
import java.text.ParseException;
import java.util.Date;

import com._51cto.healthy.content.R;
import com._51cto.healthy.pojo.Order;
import com._51cto.healthy.service.OrderService;
import io.swagger.models.auth.In;
import lombok.SneakyThrows;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class OrderController {

    @DubboReference
    private OrderService orderService;

    @ResponseBody
    @SneakyThrows
    @PostMapping("/reservation")
    public R reservation(
            @RequestParam("doctor") Integer doctor,
            @RequestParam("setmeal") Integer setmeal,
            @RequestParam("date") String date
            ) throws ParseException {

        Order order = new Order();
        order.setMemberId(82);
        order.setOrderDate(DateUtils.parseDate(date, "yyyy-MM-dd"));
        order.setOrderType("网络预约");
        order.setOrderStatus("未到诊");
        order.setSetMealId(setmeal);

        orderService.reservation(order,doctor);
        return R.success("预约成功");
    }


}
